package tr.edu.metu.is.mega.client.core;

import tr.edu.metu.is.mega.client.widgets.ConstraintDecorator;

import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.google.gwt.user.client.Element;

/**
 * Abstract base class for main windows. (Windows which are opened from main
 * menu).
 * 
 */
public abstract class MainWindow extends ContentPanel {

    private final String featureIdentifier;

    private final String className;

    /**
     * Default constructor.
     * 
     * @param featureIdentifier feature identifier
     * @param className class name to be managed in this screen
     */
    public MainWindow(String featureIdentifier, String className) {
        this.featureIdentifier = featureIdentifier;
        this.className = className;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void onRender(Element parent, int pos) {
        super.onRender(parent, pos);
        manageConstraints();
    }

    /**
     * Set constraints of components.
     */
    private void manageConstraints() {
        if (className != null) {
            ConstraintDecorator decorator = new ConstraintDecorator();
            decorator.decorateComponents(className, this);
        }
    }

    /**
     * Returns feature identifier of this.
     * 
     * @return feature identifier
     */
    public String getFeatureIdentifier() {
        return featureIdentifier;
    }

}
